import React, { Component } from 'react'
import Header from '../../components/Header/Header'
import { Button, Form, Input, Toast } from "antd-mobile";
import { reqlogin } from "../../http/api";




export default class Login extends Component {
  constructor(){
    super()
    this.state={
      user:{
        phone:"",
        password:""
      }
    }
  }
   //登录
   async login() {
    let res = await reqlogin(this.state.user);
    if (res.data.code === 200) {
      Toast.show({
        content: res.data.msg,
      });
      //存信息
      sessionStorage.setItem("userInfo",JSON.stringify(res.data.list))
      //跳页面
      this.props.history.push("/index/home");
    }
  }
  
  render() {
    return (
      <div>
        <Header register title="登录"></Header>
       

        <Form layout='horizontal'>
          <Form.Item label='用户名' name='username'>
            <Input placeholder='请输入用户名' clearable 
             onChange={(v) => {
              this.setState({
                user: {
                  ...this.state.user,
                  phone: v,
                },
              });
            }} />
          </Form.Item>
          <Form.Item label='密码' name='password'>
            <Input placeholder='请输入密码' clearable type='password'
            onChange={(v) =>
              this.setState({ user: { ...this.state.user, password: v } })
            } />
          </Form.Item>
        </Form>
        <Button size="small" color="primary" onClick={() => this.login()}>
          登录
        </Button>
      </div>
    )
  }
}
